<!--登录-->
<div class="land">	
	<a href="javascript:;" id="landbottom1" class="landTop landTop1">登录</a>
	<a href="javascript:;" id="landbottom2" class="landTop">注册</a>
	<a href="javascript:;" class="x">×</a>
	<div class="landbottom landbottom1">
		<form action="{{U('Login/login')}}" method="post">
			<ul>
				<li>
					<span><img src="./Public/Home/images/username.jpg" alt="" /></span>
					<input type="text" name="username" id="" placeholder="请输入手机号" class="user"/>
				</li>
				<li>
					<span><img src="./Public/Home/images/password.jpg" alt="" /></span>
					<input type="password" name="password" id="" placeholder="请输入密码" class="user"/>
				</li>
				<li style="margin-top: 20px;">
					<input type="checkbox" name="" id="" checked="checked"/>
					<sp>自动登录</sp>
				</li>
				<li style="margin-top: 0;">
					<input type="submit" value="登录" class="button"/>
				</li>
			</ul>
		</form>
	</div>
	<div class="landbottom landbottom2">
		<form action="javascript:;" onsubmit="submits(this,'{{U('Login/register')}}')" method="post">
			<ul>
				<li>
					<sp>账号：</sp>
					<input type="text" name="username" id="" class="shuru" placeholder="请输入手机号"/>
					<span id="msg"></span>
				</li>
				<li>
					<sp>密码：</sp>
					<input type="password" name="password" id="password" class="shuru" placeholder="请输入密码"/>
				</li>
				<li>
					<sp>确认密码：</sp>
					<input type="password" name="confirmPassword" id="confirmPassword" class="shuru" placeholder="请再次输入密码"/>
					<span class="msg"></span>
				</li>
				<li>
					<sp>验证码：</sp>
					<input type="text" name="" id="code" class="shuru" style="width: 110px;"/>
					<img src="{{U('Login/code')}}" onclick="this.src = this.src + '&mt=' + Math.random()" alt=""/>
					<span class="code" style="margin-right: 200px;"></span>
				</li>
				<li>
					<input type="checkbox" name="" id="" checked="checked" style="margin-left: 120px;"/>
					<spa>同意联想的 <a href="" style="color: blue;">使用条款</a> 和 <a href="" style="color: blue;">隐私权政策</a></spa>
				</li>
				<li>
					<input type="submit" value="立即注册" class="button"/>
				</li>
			</ul>
		</form>
	</div>
</div>
<div class="zhezhao"></div>

<script type="text/javascript">
	function submits(obj,url){
		var preg = /(\+86)?1[2-9]\d{9}/;
		if(!obj['username'].value.match(preg)){
			alert('用户名不合法');
			return;
		}
		if(obj['confirmPassword'].value != obj['password'].value){
			alert('2次密码不一致');
			return;
		} 
		var data = $(obj).serialize();
		var username = obj['username'].value;
		var password = obj['password'].value;
		var confirmPassword = obj['confirmPassword'].value;
		var code = obj['code'].value;
		$.ajax({
			type:"post",
			url:url,
			data:{username:username,password:password,confirmPassword:confirmPassword,code:code},
			success:function(data){
				var data = $.parseJSON(data);
				if(data.error == 1){
					alert(data.msg);
				}else{
					obj['username'].value = '';
					obj['password'].value = '';
					obj['confirmPassword'].value = '';
					obj['code'].value = '';
					alert(data.msg);
					$('.land').hide();
					$('.zhezhao').hide();
				}
			}
		});
	}
	$(function(){
		$('input[name=username]').blur(function(){
			var preg = /(\+86)?1[2-9]\d{9}/;
			var pregs = $(this).val().match(preg);
			var username = this;
			var uname = $(this).val();
			$.ajax({
				type:"post",
				url:"{{U('Login/username')}}",
				data:{uname:uname,pregs:pregs},
				dataType:"json",
				success:function(data){
					if(data == 1){
						username.error = 1;
						$('#msg').html('<span style="color:red;">用户名已存在</span>');
					}else{
						username.error = 0;
						$('#msg').html('<span style="color:green;">可以注册</span>');
					}
					if(data == 2){
						username.error = 1;
						$('#msg').html('<span style="color:red;">请输入用户名</span>');
					}
					if(data == 3){
						username.error = 1;
						$('#msg').html('<span style="color:red;">用户名不合法</span>');
					}
				}
			})
		})
			
		$('input[name=confirmPassword]').blur(function(){
			var upassword = this;
			var password = $('#password').val();
			var confirmPassword = $('#confirmPassword').val();
			$.ajax({
				type:"post",
				url:"{{U('Login/password')}}",
				data:{password:password,confirmPassword:confirmPassword},
				dataType:"json",
				success:function(data){
					if(data == 1){
						confirmPassword.error = 1;
						$('.msg').html('<span style="color:red;">2次密码不一致</span>');
					}else{
						confirmPassword.error = 0;
						$('.msg').html('<span style="color:green;">可以注册</span>');
					}
					if(data == 2){
						confirmPassword.error = 1;
						$('.msg').html('<span style="color:red;">请输入密码</span>');
					}
				}
			})
		})
		
		$('#code').blur(function(){
			var codes = this;
			var code = $(this).val();
			$.ajax({
				type:"post",
				url:"{{U('Login/codes')}}",
				data:{code:code},
				dataType:"json",
				success:function(data){
					if(data == 1){
						codes.error = 1;
						$('.code').html('<span style="color:red;">请输入验证码</span>');
					}else{
						$('.code').html('<span style="color:green;">验证通过</span>');
					}
					if(data == 2){
						$('.code').html('<span style="color:red;">验证码错误</span>');
					}
				}
			})
		})
	})
</script>